/***************************************************************************//**
 * @file GUI/PaneData.cpp
 * @author  Marek M. Cel <marekcel@mscsim.org>
 *
 * @section LICENSE
 *
 * Copyright (C) 2013 Marek M. Cel
 *
 * This file is part of MScSim. You can redistribute and modify it under
 * the terms of GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.
 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Further information about the GNU General Public License can also be found
 * on the world wide web at http://www.gnu.org.
 ******************************************************************************/
#ifndef PANE_DATA_CPP
#define PANE_DATA_CPP
#endif

////////////////////////////////////////////////////////////////////////////////

#include <QSettings>

#include <mscsim_defs.h>

#include <GUI/PaneData.h>
#include <ui_PaneData.h>

////////////////////////////////////////////////////////////////////////////////

PaneData::PaneData( QWidget *parent ) :
    QDockWidget ( parent ),
    m_ui ( new Ui::PaneData )
{
    m_ui->setupUi( this );
    
    settingsRead();
}

////////////////////////////////////////////////////////////////////////////////

PaneData::~PaneData()
{
    settingsWrite();
    
    if ( m_ui ) delete m_ui; m_ui = 0;
}

////////////////////////////////////////////////////////////////////////////////

void PaneData::settingsRead()
{
    QSettings settings( MSCSIM_ORG_NAME, MSCSIM_APP_NAME );
    
    settings.beginGroup( "pane_data" );
    {
        settings.beginGroup( "units_combos" );
        {
            m_ui->comboAltitudeASL  ->setCurrentIndex( settings.value( "altitude_asl" , 0 ).toInt() );
            m_ui->comboAltitudeAGL  ->setCurrentIndex( settings.value( "altitude_agl" , 0 ).toInt() );
            m_ui->comboAirspeed     ->setCurrentIndex( settings.value( "airspeed"     , 0 ).toInt() );
            m_ui->comboClimbRate    ->setCurrentIndex( settings.value( "climb_rate"   , 0 ).toInt() );
            m_ui->comboMachNo       ->setCurrentIndex( settings.value( "mach_no"      , 0 ).toInt() );
            m_ui->comboRollAngle    ->setCurrentIndex( settings.value( "roll_angle"   , 1 ).toInt() );
            m_ui->comboPitchAngle   ->setCurrentIndex( settings.value( "pitch_angle"  , 1 ).toInt() );
            m_ui->comboYawAngle     ->setCurrentIndex( settings.value( "yaw_angle"    , 1 ).toInt() );
            m_ui->comboAoA          ->setCurrentIndex( settings.value( "aoa"          , 1 ).toInt() );
            m_ui->comboSideslip     ->setCurrentIndex( settings.value( "sideslip"     , 1 ).toInt() );
            m_ui->comboPathAngle    ->setCurrentIndex( settings.value( "path_angle"   , 1 ).toInt() );
            m_ui->comboVelCourse    ->setCurrentIndex( settings.value( "vel_course"   , 1 ).toInt() );
            m_ui->comboRollRate     ->setCurrentIndex( settings.value( "roll_rate"    , 1 ).toInt() );
            m_ui->comboPitchRate    ->setCurrentIndex( settings.value( "pitch_rate"   , 1 ).toInt() );
            m_ui->comboYawRate      ->setCurrentIndex( settings.value( "yaw_rate"     , 1 ).toInt() );
            m_ui->comboGx           ->setCurrentIndex( settings.value( "gx"           , 0 ).toInt() );
            m_ui->comboGy           ->setCurrentIndex( settings.value( "gy"           , 0 ).toInt() );
            m_ui->comboGz           ->setCurrentIndex( settings.value( "gz"           , 0 ).toInt() );
            m_ui->comboMaxGz        ->setCurrentIndex( settings.value( "max_gz"       , 0 ).toInt() );
        }
        settings.endGroup();
    }
    settings.endGroup();
}

////////////////////////////////////////////////////////////////////////////////

void PaneData::settingsWrite()
{
    QSettings settings( MSCSIM_ORG_NAME, MSCSIM_APP_NAME );
    
    settings.beginGroup( "pane_data" );
    {
        settings.beginGroup( "units_combos" );
        {
            settings.setValue( "altitude_asl" , m_ui->comboAltitudeASL  ->currentIndex() );
            settings.setValue( "altitude_agl" , m_ui->comboAltitudeAGL  ->currentIndex() );
            settings.setValue( "airspeed"     , m_ui->comboAirspeed     ->currentIndex() );
            settings.setValue( "climb_rate"   , m_ui->comboClimbRate    ->currentIndex() );
            settings.setValue( "mach_no"      , m_ui->comboMachNo       ->currentIndex() );
            settings.setValue( "roll_angle"   , m_ui->comboRollAngle    ->currentIndex() );
            settings.setValue( "pitch_angle"  , m_ui->comboPitchAngle   ->currentIndex() );
            settings.setValue( "yaw_angle"    , m_ui->comboYawAngle     ->currentIndex() );
            settings.setValue( "aoa"          , m_ui->comboAoA          ->currentIndex() );
            settings.setValue( "sideslip"     , m_ui->comboSideslip     ->currentIndex() );
            settings.setValue( "path_angle"   , m_ui->comboPathAngle    ->currentIndex() );
            settings.setValue( "vel_course"   , m_ui->comboVelCourse    ->currentIndex() );
            settings.setValue( "roll_rate"    , m_ui->comboRollRate     ->currentIndex() );
            settings.setValue( "pitch_rate"   , m_ui->comboPitchRate    ->currentIndex() );
            settings.setValue( "yaw_rate"     , m_ui->comboYawRate      ->currentIndex() );
            settings.setValue( "gx"           , m_ui->comboGx           ->currentIndex() );
            settings.setValue( "gy"           , m_ui->comboGy           ->currentIndex() );
            settings.setValue( "gz"           , m_ui->comboGz           ->currentIndex() );
            settings.setValue( "max_gz"       , m_ui->comboMaxGz        ->currentIndex() );
        }
        settings.endGroup();
    }
    settings.endGroup();
}
